package study06;

public class Java04_Thread_run {
    public static void main (String arg[]) throws Exception {
//        线程 - 运行
//        MyThread3 t3 = new MyThread3();
//        t3.start();
//
//        MyThread4 t4 = new MyThread4();
//        t4.start();

        MyThread5 t5 = new MyThread5("t5");
        t5.start();

        MyThread5 t55 = new MyThread5("t55");
        t55.start();

//        传递逻辑时需要遵循规则 () -> { 逻辑 } Lambda表达式
        Thread T6 = new Thread(() -> {
            System.out.println("t6线程执行");
        });
        T6.start();

//        也可以传递实现了 Runnable 接口的类的对象, 一般使用匿名类
        Thread T7 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("t7线程执行");
            }
        });
        T7.start();

        System.out.println("main线程执行");
    }
}

class MyThread3 extends Thread {
    @Override
    public void run() {
        System.out.println("t3 线程执行");
    }
}

class MyThread4 extends Thread {
    @Override
    public void run() {
        System.out.println("t4 线程执行");
    }
}

class MyThread5 extends Thread {
    private String ThreadName;

    public MyThread5(String ThreadName) {
        this.ThreadName = ThreadName;
    }

    @Override
    public void run() {
        System.out.println(this.ThreadName + " 线程执行");
    }
}
